﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.Universal;

/// <summary>
/// 屏幕空间反射功能
/// </summary>
public class SSRPFeature : ScriptableRendererFeature
{
    public struct Thread
    {
        public int GroupThreadX;//组内线程id x分量
        public int GroupThreadY;//组内线程id y分量
        public int GroupX;//线程组id x分量
        public int GroupY;//线程组id y分量
    }

    [System.Serializable]
    public class Setting
    {
        [Header("Settings")]
        public bool On = true;
        public float ReflectHeight = 0.01f;

        [Range(128, 2048)]
        public int RTSize = 512;

        [Range(0, 1)]
        public float FadeOutRange = 0.3f;

        public bool HDR = true;
        public bool ApplyFillHoleFix = true;

        /// <summary>
        /// 渲染阶段
        /// </summary>
        public RenderPassEvent evenPlugin = RenderPassEvent.AfterRenderingTransparents;

        public string CmdName = "ScreenSpacePlaneReflect";
    }

    /// <summary>
    /// 配置相关设置
    /// </summary>
    public Setting setting;

    /// <summary>
    /// 渲染通道
    /// </summary>
    public ScreenSpacePlaneReflectionPass SSPRPass;

    /// <summary>
    /// 屏幕空间采样运算着色器
    /// </summary>
    public ComputeShader SSPRShader;

    public override void Create()
    {
        SSPRPass = new ScreenSpacePlaneReflectionPass(setting, SSPRShader);
        SSPRPass.renderPassEvent = setting.evenPlugin;
    }


    public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
    {
        renderer.EnqueuePass(SSPRPass);
    }


}
